package com.toncen.samepms.fisher.formatter;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.toncen.samepms.net.dao.ChannelDao;
import com.toncen.samepms.net.domain.Channel;
import com.toncen.samepms.net.domain.RoleChannel;
import com.toncen.samepms.system.dao.RoleDao;
import com.toncen.samepms.system.domain.Role;
import com.toncen.samepms.util.SQLUtils;
import com.sky.fisher.formatter.AbstractFormatter;
import com.sky.fisher.model.CommonColumnModel;

public class ChannelFormatter extends AbstractFormatter{

	@Override
	public String format(CommonColumnModel column, String source) throws Exception {
		ChannelDao channelDao = new ChannelDao();
		Channel channel = channelDao.find(Long.parseLong(source));
		List<RoleChannel> roleChannels = channel.getRoleChannels();
		Set<Long> roleIds = new HashSet<Long>();
		for(RoleChannel roleChannel : roleChannels){
			roleIds.add(roleChannel.getRole().getId());
		}
		
		List<Role> roles = new ArrayList<Role>();
		RoleDao roleDao = new RoleDao();
		for(Long roleId : roleIds){
			roles.add(roleDao.find(roleId));
		}
		
		return SQLUtils.getInSQL(roles,"name");
		
//		return SQLUtils.getInSQL(roleChannels,"role.id");
	}

}
